﻿using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMS_Master.Dto;
using TMS_Master.Entities;
using TMS_Master.Interface;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using System.Linq.Expressions;
using System.Security.Claims;
using Microsoft.IdentityModel.Tokens;
using Microsoft.Extensions.Options;
using System.IdentityModel.Tokens.Jwt;
using System.Threading;

namespace TMS_Master.DomainService
{
    public class LoginService : ApplicationService, ILoginService
    {
        /// <summary>
        /// 依赖注入
        /// </summary>
        private readonly IRepository<UserInfo> _userInfoRepository;

        public LoginService(IRepository<UserInfo> userInfoRepository)
        {
            _userInfoRepository = userInfoRepository;
        }

        /// <summary>
        /// 异步登录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<UserInfoDto> Login(string username="", string password="")
        {
            //async await 异步 
            var user = await _userInfoRepository.GetAsync(x => x.LoginName == username && x.LoginPwd == password);
            //转换成用户Dto  原数据 映射数据
            var dto = ObjectMapper.Map<UserInfo, UserInfoDto>(user);
            //返回
            return dto;
        }
    }
}
